package com.tulele.vtool.handler;

import com.google.common.collect.Maps;
import com.tulele.vtool.model.BFloorPlan;
import com.tulele.vtool.model.respEntity.RespData;
import com.tulele.vtool.model.respEntity.ReturnCode;
import com.tulele.vtool.service.BFloorPlanService;
import com.tulele.vtool.service.IUserBrandInfoService;
import com.tulele.vtool.service.IUserInfoService;
import io.micrometer.core.instrument.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 户型图片表(BFloorPlan)表控制层
 *
 * @author makejava
 * @since 2020-08-05 08:39:12
 */
@Slf4j
@RestController
public class BFloorPlanHandler {
    @Autowired
    private IUserBrandInfoService userBrandInfoService;

    @Autowired
    private IUserInfoService userInfoService;
    /**
     * 服务对象
     */
    @Resource
    private BFloorPlanService bFloorPlanService;

    /**
     * 查询多条数据
     *
     * @param bFloorPlan 实例对象
     * @return 实例对象
     */
    @PostMapping(value = "/queryAllConf", produces = "application/json;charset=UTF-8")
    public RespData queryAllConf(@RequestHeader("userId") String userId,@RequestBody BFloorPlan bFloorPlan) {
        bFloorPlan.setUserId(Integer.valueOf(userId));

        List<BFloorPlan> bFloorPlanService = this.bFloorPlanService.queryAllConf(bFloorPlan);
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(1);
        resultMap.put("bFloorPlanService", bFloorPlanService);

        RespData respData = new RespData();
        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("查询成功");
        return respData;
    }

    /**
     * 添加单条数据
     *
     * @param
     * @return 插入单条数据
     */
    @PostMapping(value = "/addFloorPlan", produces = "application/json;charset=UTF-8")
    public RespData addFloorPlan(@RequestHeader("userId") String userId,@RequestBody BFloorPlan bFloorPlan) {
        RespData respData = new RespData();

        if (null == bFloorPlan || StringUtils.isBlank(userId)){
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }

        bFloorPlan.setUserId(Integer.valueOf(userId));
        bFloorPlan.setCreateTime(new Date());
        bFloorPlan.setUpdateTime(new Date());
        bFloorPlan.setFloorFlag(1);
        this.bFloorPlanService.addFloorPlan(bFloorPlan);

        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("添加成功");
        return respData;
    }

    /**
     * 通过主键修改数据,户型图片假删除
     *
     * @param
     * @return 单条数据
     */
    @PostMapping(value = "/deleteFloorPlan", produces = "application/json;charset=UTF-8")
    public RespData deleteFloorPlan(@RequestHeader("userId") String userId,@RequestBody BFloorPlan bFloorPlan) {

        this.bFloorPlanService.deleteById(bFloorPlan.getId());

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("删除成功");
        return respData;
    }

}
